from typing import Type, Dict, Any


class ClassInfo:
    def __init__(self, **kwargs):
        self.name = kwargs.get('name')
        self.category = kwargs.get('category')
        self.plug = kwargs.get('plug', True)
        # self.version = kwargs.get('version', '1.0')


# 装饰器：用于给类添加标注
def annotate(*annotations):
    def decorator(cls: Type):
        # 存储标注信息的属性
        if not hasattr(cls, '_annotations'):
            cls._annotations = {}

        # 将标注按类型存储
        for annotation in annotations:
            cur_type = type(annotation).__name__
            cls._annotations[cur_type] = annotation

        return cls

    return decorator


# 工具类：用于获取类的标注
class AnnotationHelper:
    @staticmethod
    def get_annotations(cls: Type) -> Dict[str, Any]:
        """获取类的所有标注"""
        return getattr(cls, '_annotations', {}).copy()

    @staticmethod
    def get_annotation(cls: Type, annotation_type: str) -> Any:
        """获取指定类型的标注"""
        annotations = getattr(cls, '_annotations', {})
        return annotations.get(annotation_type)


# 使用示例
@annotate(
    ClassInfo(
        name="用户管理服务",
        category="服务类",
    )
)
class UserService:
    def create_user(self, username: str, email: str):
        pass


# 演示如何获取标注
if __name__ == "__main__":
    # 获取UserService类的所有标注
    annotations = AnnotationHelper.get_annotations(UserService)
    print("UserService的标注信息：")
    for an_type, ann in annotations.items():
        print(f"\n{an_type}:")
        print(f"  名称: {ann.name}")
        print(f"  类别: {ann.category}")
        print(f"  Plug: {ann.plug}")
